export const groupByDesc = (arr) => {
  const [...zhCN] = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫杂";
  const [...EN] = "abcdefghijklmnopqrstuvwxyz";
  // 中文在i、u、v下没有对应的汉字
  const [...desc] = "abcdefghjklmnopqrstwxyz";
  const isChinese = /[\u4e00-\u9fa5]+/;
  const isSpecial = /[0-9*#@!%$&(),.+-]+/;
  const hashMap = {};

  function findIndex(obj) {
    for (let i = 0; i < isChinese.test(obj) ? zhCN.length : EN.length; i++) {
      if (obj.localeCompare(isChinese.test(obj) ? zhCN[i] : EN[i]) <= 0) {
        return i >= 1 ? i - 1 : 0;
      }
    }
    return 22;
  }

  arr.forEach((item) => {
    let hashCode = isChinese.test(item.name)
      ? desc[findIndex(item.name)]
      : EN[findIndex(item.name)];
    isSpecial.test(item.name) ? (hashCode = "symbol") : "";
    if (!hashMap[hashCode]) {
      hashMap[hashCode] = [];
    }

    hashMap[hashCode].push(item);
  });
  return hashMap;
};
